package com.bci.pwtz.task.thread;

import java.util.Date;
import java.util.Iterator;
import java.util.Map;

import org.apache.log4j.Logger;

import com.bci.pwtz.common.PwtzConstants;

public class ClearTokenThread extends BaseThread
{
    private final static Logger _logger = Logger.getLogger(ClearTokenThread.class);
    public ClearTokenThread()
    {
        interval = PwtzConstants.CLEAR_TOKEN_INTERVAL;
        threadName = "清理过期票据任务";
    }
    
    @Override
    public void doWork()
    {
        Iterator<Map.Entry<String, Date>> itr = PwtzConstants.TOKEN_MAP.entrySet().iterator();
        Date expireDate = null;
        while(itr.hasNext())
        {
            
            Map.Entry<String, Date> i = itr.next(); 
            String token = i.getKey();
            _logger.info("Token:"+token);
            expireDate = i.getValue(); 
            Date currentDate = new Date();
            if(expireDate.before(currentDate))
            {
                itr.remove();
                if(_logger.isDebugEnabled())
                {            
                    _logger.debug("票据移除成功,Token="+token);
                }
            }
        }        
    }
}
